package com.seattleweb.gdocdump;

import org.gnome.gdk.Event;
import org.gnome.gtk.Gtk;
import org.gnome.gtk.Menu;
import org.gnome.gtk.MenuBar;
import org.gnome.gtk.MenuItem;
import org.gnome.gtk.VBox;
import org.gnome.gtk.Widget;
import org.gnome.gtk.Window;
import org.gnome.gtk.WindowPosition;

/**
 * ZetCode Java Gnome tutorial
 *
 * This program creates a simple menu.
 *
 * @author jan bodnar
 * website zetcode.com
 * last modified March 2009
 */


public class GSimpleMenu extends Window {


    public GSimpleMenu() {
    
        setTitle("Simple menu");
        
        initUI();
    
        setDefaultSize(250, 200);
        setPosition(WindowPosition.CENTER);
        showAll();
    }    
    
    private void initUI() {
    
        connect(new Window.DeleteEvent() {
            public boolean onDeleteEvent(Widget source, Event event) {
               Gtk.mainQuit();
               System.exit(0);
                return false;
            }
        });
    
        VBox vbox = new VBox(false, 0);
        
        MenuBar menuBar = new MenuBar();
        MenuItem fileItem = new MenuItem("File");
        menuBar.append(fileItem);
        
        Menu quitMenu = new Menu();
        MenuItem quitItem = new MenuItem("Quit");
        
        quitItem.connect(new MenuItem.Activate() {

            public void onActivate(MenuItem menuItem) {
        	
        	try{
        	
        	    
        	//System.exit(1);
                Gtk.mainQuit();
        	}catch(Throwable t){
        	    t.printStackTrace();
        	}
            }
        });
        
        quitMenu.append(quitItem);
        fileItem.setSubmenu(quitMenu);
        
        vbox.packStart(menuBar, false, false, 3);
        add(vbox);
    }
    
    public static void main(String[] args) {
        
        Gtk.init(args);
        new GSimpleMenu();
        Gtk.main();   
    }
}
